package com.guaju.yueshangLife.fragment.order;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsoluteLayout;

import com.guaju.yueshangLife.BR;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.activity.GoodsDetailActivity;
import com.guaju.yueshangLife.activity.MainActivity;
import com.guaju.yueshangLife.activity.OrderListActivity;
import com.guaju.yueshangLife.adapter.CommonRecyclerViewAdapter;
import com.guaju.yueshangLife.adapter.OrderListAdapter;
import com.guaju.yueshangLife.base.BaseFragment;
import com.guaju.yueshangLife.bean.Goods;
import com.guaju.yueshangLife.bean.GoodsListTotal;
import com.guaju.yueshangLife.bean.MeOrder;
import com.guaju.yueshangLife.databinding.FragmentOrderListBinding;
import com.guaju.yueshangLife.global.BaseApplication;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.CommonUtils;
import com.guaju.yueshangLife.utils.Utils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class OrderListFragment extends BaseFragment<FragmentOrderListBinding> {
    public static final String TYPE = "type";

    private static OrderListFragment orderListFragment;
    public View news_loading;

    @Override
    public int setContent() {
        return R.layout.fragment_order_list;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        if (view != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
            }
            return view;
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public static OrderListFragment getInstance(String type) {
        if (TextUtils.equals("all", type)) {
            orderListFragment = new TotalFragment();
        } else if (TextUtils.equals("pay", type)) {
            orderListFragment = new UnpayFragment();
        } else if (TextUtils.equals("ship", type)) {
            orderListFragment = new UnreceivedFragment();
        } else if (TextUtils.equals("comment", type)) {
            orderListFragment = new UncommentFragment();
        } else if (TextUtils.equals("cancel", type)) {
            orderListFragment = new CancleFragment();
        }
        Bundle bundle = new Bundle();
        bundle.putString(TYPE, type);
        orderListFragment.setArguments(bundle);
        return orderListFragment;
    }







    @Override
    public abstract  void loadData();

    public void addProgressPic() {
        news_loading = View.inflate(getActivity(), R.layout.loading, null);
        news_loading.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.MATCH_PARENT, 0, 0));
        Bitmap mBgBitmap = Utils.readBitMap(getActivity(), R.drawable.order_loading);
        news_loading.setBackgroundDrawable(new BitmapDrawable(mBgBitmap));
        bindingView.rlContainer.addView(news_loading);
        news_loading.setVisibility(View.VISIBLE);
    }

}
